<?php
/**
 * Created by PhpStorm.
 * User: zd
 * Date: 2018/11/2
 * Time: 14:40
 */

namespace app\api\model;


class CardExtend extends BaseModel
{
    protected $hidden=['audio_id','w_id','create_time','update_time','delete_time'];
    protected $autoWriteTimestamp = true;

    /**
     * 默认值处理
     * @param $value
     * @return string
     */
    public function getShardWordAttr($value){
        if (empty($value)){
            $value = '这是我的名片，望惠存！';
        }
        return $value;
    }

    /**
     * 默认值处理
     * @param $value
     * @return string
     */
    public function getWelcomeWordAttr($value){
        if (empty($value)){
            $value = '欢迎来到我的名片，有什么需要请联系我！';
        }
        return $value;
    }

    /**
     * 与card_audio一对一
     * @return \think\model\relation\HasOne
     */
    public function audio(){
        return $this->belongsTo('CardAudio','audio_id','id');
    }

    /**
     * 与workuser一对一关系
     * @return \think\model\relation\BelongsTo
     */
    public function workuser(){
        return $this->belongsTo('WorkUser','w_id','id');
    }

    /**
     * 获取介绍信息
     * @param $wu_id
     * @return array|false|\PDOStatement|string|\think\Model
     */
    public static function getInfo($wu_id){
       return self::with(['audio'])
                ->where('w_id','=',$wu_id)
                ->find();
    }

    /**
     * 添加拓展信息
     * @param $data
     * @return false|int
     */
    public static function addInfo($data,$wu_id){
        $data['w_id'] = $wu_id;
       $extend = new CardExtend();
       $result =  $extend->save($data);
       return $result;
    }

    /**
     * 更新拓展信息
     * @param $data
     * @param $wu_id
     * @return false|int
     */
    public static function updateInfo($data,$wu_id){
        $extend = new CardExtend();
        $result = $extend->save($data,['id'=>$data['id']]);
        return $result;
    }
    /**
     * 获取分享语
     * @param $wu_id
     * @return array|false|\PDOStatement|string|\think\Model
     */
    public static function getShareWord($wu_id)
    {
        $result = self:: where('w_id', '=', $wu_id)
            ->field('id,share_word')
            ->find();
        return $result;
    }

    /**
     * 获取欢迎语
     * @param $wu_id
     * @return array|false|\PDOStatement|string|\think\Model
     */
    public static function getWelcomeWord($wu_id){
        return self:: where('w_id','=',$wu_id)->field('id,welcome_word')->find();
    }


}